using Godot;
using System;

public class UIElement : Control
{
    // Declare member variables here. Examples:
    // private int a = 2;
    // private string b = "text";

    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {

    }
    
    private bool _isPreselect;
    
    [Export]
    private Color _preselectColor = ColorUtil.FromHSV(180, 0.65f, 0.75f, 0.75f);
    
    public bool IsPreselect
    {
        get => _isPreselect;
        set
        {
            if (_isPreselect != value)
            {
                _isPreselect = value;
                Update();
            }
        }
    }
    
    public override void _Input(InputEvent @event)
    {
        base._Input(@event);
        var isPreselect = GetGlobalRect().HasPoint(GetGlobalMousePosition());
        if (isPreselect != _isPreselect)
        {
            _isPreselect = isPreselect;
            Update();
        }

    }

    public bool HitSelect(Rect2 rect)
    {
        return (rect.Intersects(GetRect()));
    }
   
    public override void _Draw()
    {
        if (_isPreselect)
            DrawRect(new Rect2(Vector2.Zero, RectSize), _preselectColor, false);
    }
}
